<template>
  <div>
    <el-button type="text" @click="centerDialogVisible = true">点击打开 Dialog</el-button>
    <el-dialog title="提示" :visible.sync="centerDialogVisible" width="40%" center>
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        status-icon
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="ruleForm.phone" type="text" autocomplete="off" />
        </el-form-item>
        <el-form-item label="昵称" prop="name">
          <el-input v-model="ruleForm.name" type="text" autocomplete="off" width="60%" />
        </el-form-item>
        <el-form-item label="真实姓名" prop="truename">
          <el-input v-model="ruleForm.truename" />
        </el-form-item>
        <el-form-item label="VIP等级" prop="vip">
          <el-input v-model="ruleForm.vip" />
        </el-form-item>
        <el-form-item label="收货地址" prop="address">
          <el-input v-model="ruleForm.address" />
        </el-form-item>
        <el-form-item label="积分" prop="integrate">
          <el-input v-model="ruleForm.integrate" />
        </el-form-item>
        <el-form-item label="区域">
          <el-cascader
            v-model="selectedOptions"
            :options="options"
            :separator="' '"
            @change="handleChange"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="creathadle">新 增</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import options from '../../../utils/country-data.js'
import { creatPetUser } from '../../../api/admin'
export default {
  data() {
    return {
      centerDialogVisible: true,
      ruleForm: {
        phone: '',
        name: '',
        truename: '',
        vip: '',
        address: '',
        area: '',
        integrate: '0'
      },
      selectedOptions: [], // 存放默认值
      options: options // 存放城市数据
    }
  },
  methods: {
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    handleChange(value) {
      this.selectedOptions = value
    },
    creathadle() {
      this.centerDialogVisible = false
      if (this.selectedOptions.length) {
        this.ruleForm.area = this.selectedOptions.join('')
      }
      creatPetUser(this.ruleForm)
    }
  }
}
</script>
